package com.king.edu.controller;

import com.king.edu.service.TPService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;

import static java.util.concurrent.Executors.newFixedThreadPool;

/**
 * @ClassName: TPController
 * @Description: TODO
 * @Author: wangchangyong
 * @Date: 2020/6/8 21:55
 * @Version: 1.0.0
 **/
@RestController
@RequestMapping("/tp")
public class TPController {

    @Reference(filter = "tpFilter")
    TPService tpService;

    @RequestMapping("/test")
    public void tpTest() throws InterruptedException {
        ExecutorService executor = newFixedThreadPool(12);
        while (true) {
            for (int i = 0; i < 4; i++) {
                executor.execute(new Thread(() -> {
                    RpcContext.getContext().setAttachment("methodName", "methodA");
                    tpService.methodA();
                }));
                executor.execute(new Thread(() -> {
                    RpcContext.getContext().setAttachment("methodName", "methodB");
                    tpService.methodB();
                }));
                executor.execute(new Thread(() -> {
                    RpcContext.getContext().setAttachment("methodName", "methodC");
                    tpService.methodC();
                }));
            }
            Thread.sleep(100);
        }
    }

}
